package fr.maistre.SystemeMarché.Implementation;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import fr.maistre.SystemeMarché.Interface.Marketable;
import fr.maistre.SystemeMarché.Interface.Stock;

public class SimpleStock implements Stock, Serializable {

	private final Map<Marketable, Integer> marchandises = new HashMap<Marketable, Integer>();

	public void ajouterMarketable(Marketable marketable, int quantité) {
		if (marchandises.containsKey(marketable)) {
			marchandises.put(marketable, marchandises.get(marketable)
					+ quantité);
		} else {
			marchandises.put(marketable, quantité);
		}
	}

	public void retirerMarketable(Marketable marketable, int quantité)
			throws Exception {
		if (marchandises.containsKey(marketable)) {
			marchandises.put(marketable, marchandises.get(marketable)
					- quantité);
		} else {
			throw new Exception("marketable not present in the set");
		}
	}

	public int getValorisation() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String toString() {
		String output = "";

		for (Map.Entry<Marketable, Integer> entry : marchandises.entrySet()) {
			output.concat(entry.getKey() + " quantity: " + entry.getValue()
					+ "\n");
		}
		return output;
	}
}
